'''
Created on Feb 22, 2012

@author: daoxuandung
'''

"""
Provide URL routing for the whole website
"""

import webapp2
from google.appengine.ext import ndb
from webapp2_extras.routes import RedirectRoute

routes = [
          # Home page
          RedirectRoute('/home/', 
                      handler='web.home_page.HomePageHandler', 
                      name = 'home-page',
                      strict_slash=True),
          
          # API
          # Bill
          RedirectRoute('/api/bill/create/', 
                      handler='api.bill.CreateHandler', 
                      name = 'bill-create',
                      strict_slash=True),
          RedirectRoute('/api/bill/read/<bill_id:\d+>/', 
                      handler='api.bill.ReadHandler', 
                      name = 'bill-read',
                      strict_slash=True),
          RedirectRoute('/api/bill/update/', 
                      handler='api.bill.UpdateHandler', 
                      name = 'bill-update',
                      strict_slash=True),
          RedirectRoute('/api/bill/delete/', 
                      handler='api.bill.DeleteHandler', 
                      name = 'bill-delete',
                      strict_slash=True),
          RedirectRoute('/api/bill/created-by-me/', 
                      handler='api.bill.CreatedBillsHandler', 
                      name = 'bill-created-by-me',
                      strict_slash=True),
          RedirectRoute('/api/bill/requested-me/', 
                      handler='api.bill.RequestedBillsHandler', 
                      name = 'bill-requested-me',
                      strict_slash=True),
          
          # Friend bill
          RedirectRoute('/api/friend-bill/update/', 
                      handler='api.friend_bill.UpdateHandler', 
                      name = 'friend-bill-update',
                      strict_slash=True),
          RedirectRoute('/api/friend-bill/delete/', 
                      handler='api.friend_bill.DeleteHandler', 
                      name = 'friend-bill-delete',
                      strict_slash=True),

          # User
          RedirectRoute('/api/user/read/', 
                      handler='api.user.ReadHandler', 
                      name = 'user-read',
                      strict_slash=True),
          RedirectRoute('/api/user/edit-email/', 
                      handler='api.user.EditEmailHandler', 
                      name = 'user-edit-email',
                      strict_slash=True),
          RedirectRoute('/api/user/edit-timezone/', 
                      handler='api.user.EditTimezoneHandler', 
                      name = 'user-edit-timezone',
                      strict_slash=True),
                   
          # Auth
          RedirectRoute('/auth/login/', 
                      handler='web.authenticate.LoginHandler', 
                      name = 'login',
                      strict_slash=True),
          RedirectRoute('/auth/openid/<provider>/', 
                      handler='web.authenticate.OpenIDHandler', 
                      name = 'openid'),
          RedirectRoute('/auth/openid-result/<provider>/', 
                      handler='web.authenticate.OpenIDResultHandler', 
                      name = 'openid-result'),
          RedirectRoute('/auth/logout/', 
                      handler='web.authenticate.LogoutHandler', 
                      name = 'logout',
                      strict_slash=True),
          RedirectRoute('/auth/register/', 
                      handler='web.authenticate.RegisterHandler', 
                      name = 'register',
                      strict_slash=True),
          RedirectRoute('/auth/facebook-login/', 
                      handler='web.authenticate.FacebookHandler', 
                      name = 'facebook-login',
                      strict_slash=True),
          RedirectRoute('/auth/confirm-email/', 
                      handler='web.authenticate.ConfirmEmailHandler', 
                      name = 'confirm-email',
                      strict_slash=True),
          RedirectRoute('/auth/reset-password/', 
                      handler='web.authenticate.ResetPasswordHandler', 
                      name = 'reset-password',
                      strict_slash=True),
          RedirectRoute('/auth/reset-password-complete/', 
                      handler='web.authenticate.ResetPasswordCompleteHandler', 
                      name = 'reset-password-complete',
                      strict_slash=True)]

config = {
          'webapp2_extras.sessions': {
                                      'secret_key': 'foo'
                                      } 
          }

#ndb.toplevel to make sure all async requests finish before handler exits
app = ndb.toplevel(webapp2.WSGIApplication(routes, config=config))